
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>插件 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../java/" />
    
    
    <link rel="prev" href="./" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    首页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="./">
            
                <a href="./">
            
                    
                    Python
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.2.1" data-path="PACKAGE.html">
            
                <a href="PACKAGE.html">
            
                    
                    插件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../java/">
            
                <a href="../java/">
            
                    
                    Java
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../java/PACKAGE.html">
            
                <a href="../java/PACKAGE.html">
            
                    
                    插件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >插件</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="python&#x63D2;&#x4EF6;">Python&#x63D2;&#x4EF6;</h1>
<h2 id="1xlrd&#x8BFB;&#x53D6;xls&#x6216;&#x8005;xlrd&#x683C;&#x5F0F;&#x7684;&#x8868;">1.xlrd(&#x8BFB;&#x53D6;xls&#x6216;&#x8005;xlrd&#x683C;&#x5F0F;&#x7684;&#x8868;)</h2>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> xlrd

<span class="hljs-comment"># ctype : 0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error</span>
workbook = xlrd.open_workbook(path)
sheet = workbook.sheet_by_index(<span class="hljs-number">0</span>)
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">3</span>, sheet.nrows):
    cell = sheet.cell(i, <span class="hljs-number">2</span>)
    value = cell.value
</code></pre>
<hr>
<h2 id="2xlsxwriter&#x5199;xlsx&#x683C;&#x5F0F;">2.xlsxwriter(&#x5199;xlsx&#x683C;&#x5F0F;)</h2>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> xlsxwriter

workbook = xlsxwriter.Workbook(<span class="hljs-string">&apos;export.xlsx&apos;</span>)
worksheet = workbook.add_worksheet()
worksheet.set_column(<span class="hljs-string">&apos;A:A&apos;</span>, <span class="hljs-number">150</span>)
workformat = workbook.add_format()
workformat.set_align(<span class="hljs-string">&apos;left&apos;</span>)
<span class="hljs-keyword">try</span>:
    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(len(UNREFERENCE_FILES)):
        worksheet.write(<span class="hljs-string">&apos;A%d&apos;</span> % (i+<span class="hljs-number">1</span>), UNREFERENCE_FILES[i])
<span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> identifier:
    <span class="hljs-keyword">pass</span>
workbook.close()
</code></pre>
<hr>
<h2 id="3requestshttp&#x8BF7;&#x6C42;">3.requests(HTTP&#x8BF7;&#x6C42;)</h2>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> requests

data = json.dumps({
    <span class="hljs-string">&apos;msgtype&apos;</span>: <span class="hljs-string">&apos;text&apos;</span>,
    <span class="hljs-string">&apos;text&apos;</span>: {
        <span class="hljs-string">&apos;content&apos;</span>: <span class="hljs-string">&apos;&#x70ED;&#x66F4;&#x65B0;&#x7248;&#x672C;-%d(%s)&#x53D1;&#x5E03;&apos;</span> % (version, args.debug <span class="hljs-keyword">and</span> <span class="hljs-string">&apos;&#x6D4B;&#x8BD5;&apos;</span> <span class="hljs-keyword">or</span> <span class="hljs-string">&apos;&#x6B63;&#x5F0F;&apos;</span>)
    }
})
r = requests.post(<span class="hljs-string">&apos;https://oapi.dingtalk.com/robot/send?access_token=%s&apos;</span> % args.dingtoken, data, headers={
                        <span class="hljs-string">&apos;Content-Type&apos;</span>: <span class="hljs-string">&apos;application/json;charset=UTF-8;&apos;</span>,
                        <span class="hljs-string">&apos;Content-Length&apos;</span>: str(len(data.encode(<span class="hljs-string">&apos;utf-8&apos;</span>)))})
</code></pre>
<hr>
<h2 id="4argparse&#x53C2;&#x6570;&#x89E3;&#x6790;">4.argparse(&#x53C2;&#x6570;&#x89E3;&#x6790;)</h2>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> argparse

parser = argparse.ArgumentParser(description=<span class="hljs-string">&apos;&#x6267;&#x884C;3&#x6B65;&#x6D41;&#x7A0B;&#xFF1A;&#x6253;&#x5305;-&gt;&#x538B;&#x7F29;-&gt;&#x4E0A;&#x4F20;&apos;</span>)
parser.add_argument(<span class="hljs-string">&apos;--project&apos;</span>, type=str,
                    default=<span class="hljs-string">&apos;E:/Work/IslandSurvival&apos;</span>, help=<span class="hljs-string">&quot;&#x9879;&#x76EE;&#x8DEF;&#x5F84;&quot;</span>)
parser.add_argument(
    <span class="hljs-string">&apos;--cocos&apos;</span>, type=str, default=<span class="hljs-string">&apos;D:/Cocos/Creator/3.3.0/CocosCreator.exe&apos;</span>, help=<span class="hljs-string">&apos;Cocos&#x5F15;&#x64CE;&#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;&apos;</span>)
parser.add_argument(
    <span class="hljs-string">&apos;--config&apos;</span>, type=str, default=<span class="hljs-string">&apos;E:/Work/IslandSurvival/extensions/publish/android/build-debug.json&apos;</span>, help=<span class="hljs-string">&apos;&#x6784;&#x5EFA;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;&apos;</span>)
parser.add_argument(
    <span class="hljs-string">&apos;--info&apos;</span>, type=str, default=<span class="hljs-string">&apos;E:/Work/IslandSurvival/tools/configs/AppConfig.xlsx&apos;</span>, help=<span class="hljs-string">&apos;&#x6E38;&#x620F;&#x914D;&#x7F6E;&#x4FE1;&#x606F;&apos;</span>)
parser.add_argument(<span class="hljs-string">&apos;--output&apos;</span>, type=str,
                    default=<span class="hljs-string">&apos;E:/Work/IslandSurvival/build/android&apos;</span>, help=<span class="hljs-string">&apos;&#x8F93;&#x51FA;&#x8DEF;&#x5F84;&apos;</span>)
parser.add_argument(<span class="hljs-string">&apos;--debug&apos;</span>, action=<span class="hljs-string">&apos;store_true&apos;</span>, help=<span class="hljs-string">&apos;&#x662F;&#x5426;&#x4E3A;&#x8C03;&#x8BD5;&#x6A21;&#x5F0F;&apos;</span>)
parser.add_argument(<span class="hljs-string">&apos;--platform&apos;</span>, type=str, default=<span class="hljs-string">&apos;android&apos;</span>, help=<span class="hljs-string">&quot;&#x6253;&#x5305;&#x7684;&#x5E73;&#x53F0;&quot;</span>)
parser.add_argument(<span class="hljs-string">&apos;--pack&apos;</span>, action=<span class="hljs-string">&apos;store_true&apos;</span>, help=<span class="hljs-string">&quot;&#x662F;&#x5426;&#x4E3A;&#x6253;&#x5305;&quot;</span>)
parser.add_argument(
    <span class="hljs-string">&apos;--dingtoken&apos;</span>, default=<span class="hljs-string">&apos;59ac40fdc4c5e5ac91e6aaea7a1ee598d5faf1a73c1f2b359c6052666e5c3e0b&apos;</span>, help=<span class="hljs-string">&quot;&#x9489;&#x9489;&#x79D8;&#x94A5;&quot;</span>)
args = parser.parse_args()
</code></pre>
<hr>
<h2 id="5zipfile-gzip-base64&#x538B;&#x7F29;">5.zipfile, gzip, base64(&#x538B;&#x7F29;)</h2>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> zipfile
<span class="hljs-keyword">import</span> base64
<span class="hljs-keyword">import</span> gzip

z = zipfile.ZipFile(<span class="hljs-string">&apos;a.zip&apos;</span>, <span class="hljs-string">&apos;w&apos;</span>)
z.write(<span class="hljs-string">&apos;path&apos;</span>, <span class="hljs-string">&apos;newPath&apos;</span>, zipfile.ZIP_DEFLATED)
z.close()

gz = gzip.GzipFile(<span class="hljs-string">&apos;test.png&apos;</span>, <span class="hljs-string">&apos;wb&apos;</span>, <span class="hljs-number">9</span>, <span class="hljs-keyword">None</span>, <span class="hljs-number">1</span>)
gz.write(original_data)
gz.close()

postData = base64.b64encode(data).decode()
</code></pre>
<hr>
<h2 id="6hashlibmd5">6.hashlib(MD5)</h2>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> hashlib

md5 = hashlib.md5(data).hexdigest()
</code></pre>
<hr>
<h2 id="7yaml&#x89E3;&#x6790;yaml">7.yaml(&#x89E3;&#x6790;YAML)</h2>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> yaml

yaml.load(data, Loader=yaml.FullLoader)
</code></pre>
<hr>
<h2 id="8mako&#x6A21;&#x677F;&#x8BED;&#x6CD5;"><strong>8.mako(&#x6A21;&#x677F;&#x8BED;&#x6CD5;))</strong></h2>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> mako.template <span class="hljs-keyword">import</span> Template
<span class="hljs-keyword">from</span> mako.exceptions <span class="hljs-keyword">import</span> RichTraceback    

<span class="hljs-keyword">try</span>:
    t = Template(filename=os.path.join(ScriptDir, self._template))
    content = t.render(entity=self)
    <span class="hljs-keyword">return</span> content
<span class="hljs-keyword">except</span>:
    traceback = RichTraceback()
    <span class="hljs-keyword">for</span> (filename, lineno, function, line) <span class="hljs-keyword">in</span> traceback.traceback:
        print(<span class="hljs-string">&quot;File %s, line %s, in %s&quot;</span> % (filename, lineno, function))
        print(line, <span class="hljs-string">&quot;\n&quot;</span>)
    print(<span class="hljs-string">&quot;%s: %s&quot;</span> %
            (str(traceback.error.__class__.__name__), traceback.error))
</code></pre>
<hr>
<h2 id="9pillow&#x56FE;&#x7247;&#x7F16;&#x8F91;"><strong>9.pillow(&#x56FE;&#x7247;&#x7F16;&#x8F91;))</strong></h2>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

<span class="hljs-keyword">try</span>:
    im = Image.open(path)
    <span class="hljs-keyword">if</span> im.size[<span class="hljs-number">0</span>] &gt; size[<span class="hljs-number">0</span>] <span class="hljs-keyword">and</span> im.size[<span class="hljs-number">1</span>] &gt; size[<span class="hljs-number">1</span>]:
        im = im.resize((size[<span class="hljs-number">0</span>], size[<span class="hljs-number">1</span>]))
        im.save(path)
<span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:
    <span class="hljs-keyword">pass</span>
</code></pre>
<hr>
<h2 id="10paddlespeech&#x97F3;&#x9891;&#x5408;&#x6210;&#xFF0C;&#x7FFB;&#x8BD1;"><strong>10.paddlespeech(&#x97F3;&#x9891;&#x5408;&#x6210;&#xFF0C;&#x7FFB;&#x8BD1;)</strong></h2>
<pre><code class="lang-python">pip install paddlepaddle paddlespeech

<span class="hljs-comment"># &#x58F0;&#x97F3;&#x5206;&#x7C7B;</span>
paddlespeech cls --input input.wav

<span class="hljs-comment"># &#x8BED;&#x97F3;&#x8BC6;&#x522B;</span>
paddlespeech asr --lang zh --input input.wav

<span class="hljs-comment"># &#x8BED;&#x97F3;&#x7FFB;&#x8BD1;</span>
paddlespeech st --input input.wav

<span class="hljs-comment"># &#x8BED;&#x97F3;&#x5408;&#x6210;</span>
paddlespeech tts --input <span class="hljs-string">&quot;&#x7FFB;&#x8BD1;&#x5185;&#x5BB9;&quot;</span> --output output.wav
</code></pre>
<hr>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="./" class="navigation navigation-prev " aria-label="Previous page: Python">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../java/" class="navigation navigation-next " aria-label="Next page: Java">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"插件","level":"1.2.1","depth":2,"next":{"title":"Java","level":"1.3","depth":1,"path":"java/README.md","ref":"java/README.md","articles":[{"title":"插件","level":"1.3.1","depth":2,"path":"java/PACKAGE.md","ref":"java/PACKAGE.md","articles":[]}]},"previous":{"title":"Python","level":"1.2","depth":1,"path":"python/README.md","ref":"python/README.md","articles":[{"title":"插件","level":"1.2.1","depth":2,"path":"python/PACKAGE.md","ref":"python/PACKAGE.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"python/PACKAGE.md","mtime":"2021-12-24T01:26:53.072Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-12-24T09:19:18.598Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

